package csu.web.mypetstore.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import csu.web.mypetstore.pojo.OrderDetail;
import csu.web.mypetstore.service.OrderDetailService;
import csu.web.mypetstore.mapper.OrderDetailMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 18632
* @description 针对表【order_detail】的数据库操作Service实现
* @createDate 2025-03-16 14:20:44
*/
@Service
public class OrderDetailServiceImpl extends ServiceImpl<OrderDetailMapper, OrderDetail>
    implements OrderDetailService{

    @Autowired
    private OrderDetailMapper orderDetailMapper;

    @Override
    public void insertOrderDetail(int orderId, String itemId, int quantity, String userid) {
            OrderDetail orderDetail = new OrderDetail();
            orderDetail.setOrderid(orderId);
            orderDetail.setItemid(itemId);
            orderDetail.setQuantity(quantity);
            orderDetail.setUserid(userid);
            orderDetailMapper.insert(orderDetail);
    }

    @Override
    public List<OrderDetail> queryOrderDetail(Integer orderId) {

        Wrapper<OrderDetail> wrapper = new LambdaQueryWrapper<OrderDetail>()
                   .eq(OrderDetail::getOrderid, orderId);


        return orderDetailMapper.selectList(wrapper);
    }
}




